package action;

import java.util.*;

import myfamily.model.GenericPerson;
import myfamily.model.RegisteredUser;

import com.opensymphony.xwork2.ActionSupport;


public class SearchAction extends ActionSupport{
	
	
	private String res;
	private String submit;
	private String searchByEmail;
	private int resultSize;
	
	
	
	public String execute(){
		
		if(submit==null){
			
			System.out.println("In Search");
			System.out.println(getSearchByEmail());
			return "showSearchPage";
			
		}
		else
		{
			
			System.out.println(getSearchByEmail());
			
			GenericPerson tmp = GenericPerson.searchByEmail(getSearchByEmail());			
				
			try{
				
				if(tmp==null){
					setResultSize(0);
					addActionError("No results for the searched member..Try a different ID");
				}else{
					setResultSize(1);
					System.out.println(tmp.getPersonName().toString());
					setRes(tmp.getPersonName().toString());
				}
			}catch(Exception e){
				
			}
		
			return "showSearchResultPage";
		}
		
	}



	public String getSubmit() {
		return submit;
	}



	public void setSubmit(String submit) {
		this.submit = submit;
	}



	public String getSearchByEmail() {
		return searchByEmail;
	}



	public void setSearchByEmail(String searchByEmail) {
		this.searchByEmail = searchByEmail;
	}



	public int getResultSize() {
		return resultSize;
	}



	public void setResultSize(int resultSize) {
		this.resultSize = resultSize;
	}



	public String getRes() {
		return res;
	}



	public void setRes(String res) {
		this.res = res;
	}



}
